package lsz.generator.seckill;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class CodeGenerator {
    public static void main(String[] args) {
        String dbUrl = "jdbc:mysql://localhost:3305/seckill?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
        FastAutoGenerator.create(dbUrl, "root", "root")
                .globalConfig(builder -> {
                    builder.author("lishaungzhi") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .disableOpenDir() //禁止打开输出目录
                            .outputDir(System.getProperty("user.dir") + "/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("lsz.seckill") // 设置父包名
                            .mapper("mapper")
                            .entity("pojo")
                            .service("service")
                            .controller("controller")
                            .serviceImpl("service.impl");
                })
                .strategyConfig(builder -> {
                    builder.addTablePrefix("t_");// 设置过滤表前缀
                    builder.entityBuilder().enableLombok();
                    builder.controllerBuilder().enableRestStyle();
                    builder.mapperBuilder()
                            .enableBaseColumnList()
                            .enableBaseResultMap()
                            .enableMapperAnnotation();
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
